COBJS-y  = cpuid.o
COBJS-y += pgtable.o

SOBJS-f = $(patsubst %,$(CURDIR)/%,$(SOBJS))
COBJS-f = $(patsubst %,$(CURDIR)/%,$(COBJS-y))
SRCS = $(SOBJS-f:.o=.S) $(COBJS-f:.o=.c)
OBJS = $(SOBJS-f) $(COBJS-f)

DEPS = $(basename $(patsubst %,.depend.%,$(SRCS)))

.PHONY: all clean depend

all: $(BUILT_IN_OBJ)

$(BUILT_IN_OBJ): $(OBJS)
	$(LD) -r  $(LDFLAGS) -o $@ $^ 

clean:
	rm -f *.o
	rm -f .depend*

depend: .depend

.depend: $(DEPS)
	cat $(DEPS) > $@

.depend.%: %.c
	$(CC) $(CFLAGS) -MM $< >$@

.depend.%: %.S
	$(CC) $(ASFLAGS) -MM $< >$@

ifneq ($(MAKECMDGOALS),clean)
sinclude .depend
endif

